﻿package com.gengine.resource.info
{
    import flash.display.*;
    import flash.geom.*;
    import flash.system.*;

    public class SWFInfo extends ResourceInfo
    {
        private var _clip:MovieClip;
        private var _bitmapData:BitmapData;
        private var _appDomain:ApplicationDomain;

        public function SWFInfo(param1:Object)
        {
            super(param1);
            return;
        }// end function

        public function get clip() : MovieClip
        {
            return this._clip;
        }// end function

        public function get bitmapData() : BitmapData
        {
            var _loc_1:Rectangle = null;
            if (this._bitmapData == null && this._clip)
            {
                this._clip.gotoAndStop(1);
                _loc_1 = this._clip.getBounds(this._clip);
                if (_loc_1.height == 0 || _loc_1.width == 0)
                {
                }
                else
                {
                    this._bitmapData = new BitmapData(_loc_1.width, _loc_1.height, true, 0);
                    this._bitmapData.draw(this._clip, new Matrix(1, 0, 0, 1, -_loc_1.x, -_loc_1.y), null, null, null, false);
                    this._clip = null;
                }
            }
            return this._bitmapData;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            if (param1 is MovieClip)
            {
                this._clip = param1 as MovieClip;
                this._appDomain = this._clip.loaderInfo.applicationDomain;
            }
            else if (param1 is LoaderInfo)
            {
                loaderInfo = param1 as LoaderInfo;
                this._appDomain = loaderInfo.applicationDomain;
                if (loaderInfo.swfVersion >= 9)
                {
                    this._clip = loaderInfo.content as MovieClip;
                }
                else
                {
                    throw new Error(loaderInfo.url + "版本：" + loaderInfo.swfVersion);
                }
            }
            if (this._clip)
            {
                this._clip.gotoAndStop(1);
            }
            return;
        }// end function

        public function getAssetClass(param1:String) : Class
        {
            if (this._appDomain == null)
            {
                throw new Error("not initialized");
            }
            if (this._appDomain.hasDefinition(param1))
            {
                return this._appDomain.getDefinition(param1) as Class;
            }
            return null;
        }// end function

        override public function dispose() : void
        {
            isLoaded = false;
            isLoading = false;
            this._clip = null;
            this._appDomain = null;
            if (this._bitmapData)
            {
                this._bitmapData.dispose();
                this._bitmapData = null;
            }
            super.dispose();
            return;
        }// end function

        override protected function unload(param1:LoaderInfo) : void
        {
            param1.loader.unloadAndStop();
            super.unload(param1);
            return;
        }// end function

    }
}
